<%--
  Created by IntelliJ IDEA.
  User: 86157
  Date: 2023/1/31
  Time: 16:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<!-- saved from url=(0052)http://49.233.183.177:8080/addressbook/register.html -->
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">


    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>注册</title>

    <link href="${pageContext.request.contextPath}/statics/css/sb-admin-2.min.css" rel="stylesheet">
    <script src="${pageContext.request.contextPath}/statics/js/jquery-3.6.2.js"></script>
    <script src="${pageContext.request.contextPath}/statics/assets/layer/layer.js" type="text/javascript"></script>
    <script>
        $(function (){

            $("#registsubmit").click(function (){
                $("#conpwd").css({display:'none'})
                $("#conloginname").css({display:'none'})
                var num=0;
                var str="";
                $("input[type$='text'],input[type$='password']").each(function(n){
                    if($(this).val()=="")
                    {
                        layer.alert(str+=""+$(this).attr("placeholder")+"不能为空！\r\n",{
                            title: '提示框',
                            icon:0,
                        });
                        num++;
                        return false;
                    }
                });
                if(num>0){
                    return false;
                }else{
                    if ($("#regist_pwd").val()==$("#regist_pwd_con").val()){
                        $.ajax({
                            type:"post",
                            url:"${pageContext.request.contextPath}/rider/register",
                            contentType:"application/x-www-form-urlencoded",
                            dataType:"json",
                            data:{
                                'login_name':$("#regist_account").val(),
                                'login_pwd':$("#regist_pwd").val(),
                                'riderName':$("#regist_name").val(),
                                'gender':$("#gender").val(),
                                'riderPhone':$("#regist_tel").val()
                            },
                            success:function (e){
                                if (e.code==200){
                                    alert(e.message);
                                    window.location.href="${pageContext.request.contextPath}/rider/login"
                                }else {
                                    if (e.message=="用户名已存在"){
                                        $("#conloginname").css({display:'block'})
                                    }else {
                                        alert(e.message)
                                    }
                                }
                            }
                        })
                    }else {
                        $("#conpwd").css({display:'block'})
                    }
                }


            })

            // function regist(){
            //
            // }
        })
        //
    </script>
</head>

<body class="bg-gradient-primary">

<div class="container">

    <div class="card o-hidden border-0 shadow-lg my-5">
        <div class="card-body p-0">
            <!-- Nested Row within Card Body -->
            <div class="row">
                <div class="col-lg-5 d-none d-lg-block bg-register-image"></div>
                <div class="col-lg-7">
                    <div class="p-5">
                        <div class="text-center">
                            <h1 class="h4 text-gray-900 mb-4">创建账号!</h1>
                        </div>
                        <div style="display: none;color: red" id="conpwd">两次密码不一致</div>
                        <div style="display: none;color: red" id="conloginname">用户名已存在</div>
                        <form action="${pageContext.request.contextPath}/rider/register" method="post" enctype="application/x-www-form-urlencoded">
                            <div class="form-group">
                                <input type="text" class="form-control form-control-user" id="regist_account" name="login_name" placeholder="注册账号">
                            </div>
                            <div class="form-group">
                                <input type="password" class="form-control form-control-user" id="regist_pwd" name="login_pwd" placeholder="注册密码">
                            </div>
                            <div class="form-group">
                                <input type="password" class="form-control form-control-user" id="regist_pwd_con" name="login_pwd_con" placeholder="确认密码">
                            </div>
                            <div class="form-group">
                                <input type="text" class="form-control form-control-user" id="regist_name" name="riderName" placeholder="注册用户名">
                            </div>
                            <div class="form-group">
                                <input type="text" class="form-control form-control-user" id="gender" name="gender" placeholder="性别">
                            </div>
                            <div class="form-group">
                                <input type="text" class="form-control form-control-user" id="regist_tel" name="riderPhone" placeholder="电话">
                            </div>
                            <font color="red"></font>
                            <button type="button" class="btn btn-primary btn-user btn-block" id="registsubmit">注册</button>
                            <hr>
                        </form>
                        <hr>
                        <div class="text-center">
                            <a class="small" href="${pageContext.request.contextPath}/rider/login">已有账号? 登录!</a>              </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>
